<?php

class User_Model extends Default_My_Model {
    //private $tgl11=date("Y-m-d");
    private $QRY = "SELECT mt_user.id_user, mt_user.nik, mt_user.id_group_user,mt_user.is_active, last_active, mt_karyawan.nama, mt_karyawan.no_hp, mt_karyawan.email, 
                    mt_group_user.group_user
                    FROM mt_user
                    LEFT JOIN mt_karyawan ON mt_karyawan.nik = mt_user.nik
                    LEFT JOIN mt_group_user ON mt_group_user.id_group_user = mt_user.id_group_user";
    private $QRYEXPORT = "SELECT 
			mt_user.id_user AS ID_PENGGUNA,
			mt_user.nik AS NIK,
			mt_karyawan.nama AS NAMA_REKAN,
			mt_group_user.group_user AS KELOMPOK_PENGGUNA,
			mt_user.is_active AS STATUS,
			mt_user.last_active AS LOGIN_TERAKHIR 
                        count(audit_trail.log_aktor) AS JUMLAH_AKTIVITAS_HARI_INI
			FROM mt_user
			LEFT JOIN mt_karyawan ON mt_karyawan.nik = mt_user.nik
			LEFT JOIN mt_group_user ON mt_group_user.id_group_user = mt_user.id_group_user 
                        LEFT JOIN (SELECT * FROM audit_trail WHERE DATE(log_time)='2013-03-28') as audit_trail ON audit_trail.log_aktor=mt_user.id_user";
    private $EDITQRY = "SELECT * FROM mt_user ";

    function __construct()
    {
        parent::__construct();
    }
    
    public function getDataResumeUser() {
        $SQL = $this->QRY ." group by mt_user.id_user,mt_karyawan.nama,mt_karyawan.no_hp,mt_karyawan.email,mt_group_user.group_user ORDER BY mt_karyawan.id_divisi ,mt_karyawan.nama";
        $resultSet = $this->db->query($SQL);
        return $resultSet;
    }

    public function getDataUser($whr, $ct_pagelimit, $offset) {
        if ($whr != "") {
            $SQL = $this->QRY ." where mt_user.nik !='xx11xx' " . $whr ." group by mt_user.id_user,mt_karyawan.nama,mt_karyawan.no_hp,mt_karyawan.email,mt_group_user.group_user ORDER BY id_user ASC LIMIT ". $ct_pagelimit ." OFFSET ". $offset;
        } else {
            $SQL = $this->QRY ." where mt_user.nik !='xx11xx' group by mt_user.id_user,mt_karyawan.nama,mt_karyawan.no_hp,mt_karyawan.email,mt_group_user.group_user ORDER BY id_user ASC LIMIT ". $ct_pagelimit ." OFFSET ". $offset;
        }
        $resultSet = $this->db->query($SQL);
        //echo $SQL;
        return $resultSet;
    }
    
    public function getDataAllUser($whr) {
        $resultSet = array();
        if ($whr != "") {
            $resultSet['data'] = $this->db->query($this->QRY ." where mt_user.nik !='xx11xx' " . $whr . " group by mt_user.id_user,mt_karyawan.nama,mt_karyawan.no_hp,mt_karyawan.email,mt_group_user.group_user order by id_user ASC");
        } else {
            $resultSet['data'] = $this->db->query($this->QRY . " where mt_user.nik !='xx11xx' group by mt_user.id_user,mt_karyawan.nama,mt_karyawan.no_hp,mt_karyawan.email,mt_group_user.group_user order by id_user ASC");
        }
        $resultSet['query'] = $this->db->last_query();
        return $resultSet;
    }
    
    public function removeDataUser($id_user) {
        $this->db->where('id_user', $id_user);
        $this->db->delete('mt_user', $where);
    }

    public function setActiveDataUser($id_user, $arrVals) {
        $this->db->where('id_user', $id_user);
        $this->db->update("mt_user", $arrVals);
    }
}

?>
